package com.netmi.myvideopicker.adapter;

import androidx.annotation.NonNull;
import androidx.fragment.app.FragmentActivity;
import androidx.viewpager2.adapter.FragmentStateAdapter;

import com.netmi.myvideopicker.VideoPlayFragment;
import com.netmi.myvideopicker.bean.VideoItem;

import java.util.ArrayList;
import java.util.List;

/**
 * 类描述：
 * 创建人：tgw
 * 创建时间：2020/7/28
 * 修改备注：
 */
public class VideoPagerFragmentStateAdapter extends FragmentStateAdapter {

    private List<VideoItem> fragmentList = new ArrayList<>();


    public VideoPagerFragmentStateAdapter(@NonNull FragmentActivity fragmentActivity, ArrayList<VideoItem> fragmentList) {
        super(fragmentActivity);
        this.fragmentList = fragmentList;
    }


    @NonNull
    @Override
    public VideoPlayFragment createFragment(int position) {
        return VideoPlayFragment.newInstance(fragmentList,position);
    }

    @Override
    public int getItemCount() {
        return  fragmentList != null && fragmentList.size() > 0 ? fragmentList.size() : 0;
    }
}
